﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "外语等级考试 - 报考科目设置");

		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		propAdvice = getProperty("serviceFactory").getBean("cetPropertyAdvice");
		
		termDateStart = year( now() );
		
		/* 当前在校生判断 grade + schooling_length > ? */
		if ( month( now() ) < 9 ) {
			termDateStart = termDateStart - 1;
		}
		
		/* 四六级报考科目设置 */
		sql = "SELECT 
				exam_id, exam_name, 
				date_start, date_end, time_start, time_end, 
				grade_allowed, institute_allowed, 
				exam_prop, 
				exam_charge, exam_date, exam_time 
				FROM t_cet 
				ORDER BY exam_id ";
		
		queryObj = new Query( datasource=application.dnsSlave );

		rs_cet = queryObj.execute( sql=sql ).getResult();

		cetId = event.getArg("EX");
		currentTab = event.getArg("TabID", "labSetting");
		
		if ( len(cetId) ) {
			
			/* 读取指定科目 */
			sql = "SELECT 
					exam_id, exam_name, 
					date_start, date_end, time_start, time_end, 
					grade_allowed, institute_allowed, 
					exam_prop, 
					exam_charge, exam_date, exam_time 
					FROM query
					WHERE exam_id = :cetId ";
							
			queryObj = new Query( dbtype="query" );
			queryObj.setAttributes( query=rs_cet );
			queryObj.addParam( name="cetId", value=cetId, cfsqltype="cf_sql_char" );

			rs_entity = queryObj.execute( sql=sql ).getResult();
			

			if ( rs_entity.recordCount ) {
				currentTab = "labEdit";
			}

			/* 读取选课学年的授课年级、学院信息 */
			sql = "SELECT DISTINCT 
					t_class.grade, 
					t_institute.institute_id, t_institute.institute_short
					FROM t_class 
					INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id 
					INNER JOIN t_institute ON t_institute.institute_id = t_subject.institute_id 
					WHERE 
						t_class.cls_scale > 0 
						AND 
						( t_class.grade + t_subject.schooling_length ) > :yearNow 
					ORDER BY 
						 t_class.grade DESC, t_institute.institute_short";
			
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="yearNow", value=termDateStart, cfsqltype="cf_sql_char" );

			rs_subject = queryObj.execute( sql=sql ).getResult();
			
			/* 生成年级 */
			sql = "SELECT DISTINCT grade FROM query";
					
			queryObj = new Query( dbtype="query" );
			queryObj.setAttributes( query=rs_subject );

			rs_grade = queryObj.execute( sql=sql ).getResult();

			/* 生成学院 */
			sql = "SELECT DISTINCT institute_id, institute_short FROM query";
					
			queryObj = new Query( dbtype="query" );
			queryObj.setAttributes( query=rs_subject );

			rs_institute = queryObj.execute( sql=sql ).getResult();

		}
		

		targetArgs = structNew();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('cetState')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">学生报名情况</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 setting"></i>可报考科目设置
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="create">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labSetting">class="active"</cfif> id="labSetting" tabTarget="Setting">考试语言及级别</span>
						<cfif len(cetId) and rs_entity.recordCount >
							<span <cfif currentTab eq "labEdit">class="active"</cfif> id="labEdit" tabTarget="Edit">修改<cfoutput>#rs_entity.exam_name#</cfoutput>报考设置</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				
				<div id="Setting" class="tabContent">
					<div class="noticeBlock">
						<h3>可报考科目</h3>
						<hr/>
					</div>
					
					<table id="cetList" class="UIEditable">
						<thead>
							<tr>
								<td width="80"></td>
								<td width="80">考试时间</td>
								<td width="150">网上报名日期</td>
								<td width="100">报考时间段</td>
								<td width="50">报名费</td>
								<td width="25">启用</td>
								<td>年级</td>
								<td>学院</td>
								<td width="18"></td>
							</tr>
						</thead>
						<tbody>
							
							<cfloop query="rs_cet">
								
								<cfset structInsert(targetArgs, "EX", rs_cet.exam_id, true) />
								<cfset propAdvice.parseProperty( rs_cet.exam_prop ) />
								
								<tr class="editRows" rowid="<cfoutput>#rs_cet.exam_id#</cfoutput>">
									<td><strong><cfoutput>#rs_cet.exam_name#</cfoutput></strong></td>
									<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDateString(rs_cet.exam_date, 'MM/DD')#</cfoutput> <cfoutput>#datetimeAdvice.formatTimeString(rs_cet.exam_time, 'HH:MI')#</cfoutput></span></td>
									<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDateString(rs_cet.date_start, 'YYYY/MM/DD')#</cfoutput> - <cfoutput>#datetimeAdvice.formatDateString(rs_cet.date_end, 'MM/DD')#</cfoutput></span></td>
									<td>
										<cfif rs_cet.time_start eq "0001" and rs_cet.time_end eq "2359">
											全天
											<cfelse>
											<span class="numeric"><cfoutput>#datetimeAdvice.formatTimeString(rs_cet.time_start, 'HH:MI')#</cfoutput> ~ <cfoutput>#datetimeAdvice.formatTimeString(rs_cet.time_end, 'HH:MI')#</cfoutput></span>	
										</cfif>
									</td>
									<td><span class="numeric"><cfoutput>#numberFormat(rs_cet.exam_charge, '__.__')#</cfoutput></span></td>
									<td><a usage="Running" rowid="<cfoutput>#rs_cet.exam_id#</cfoutput>" href="javascript:void(0);" class="stat <cfif propAdvice.getRunning()>yes<cfelse>no</cfif>"></a></td>
									<td><cfif rs_cet.grade_allowed eq "ALL">全部<cfelse><span class="numeric"><cfoutput>#replace(rs_cet.grade_allowed, ",", " | ", "all")#</cfoutput></span></cfif></td>
									<td>
										<cfif rs_cet.institute_allowed eq "ALL">全部
											<cfelse>
												<cfscript>
													sql = "SELECT institute_short FROM t_institute WHERE institute_id IN (:depIds) ";
		
													queryObj = new Query( datasource=application.dnsSlave );
													queryObj.addParam( name="depIds", value=rs_cet.institute_allowed, cfsqltype="cf_sql_char", list=true );

													rs_selected = queryObj.execute( sql=sql ).getResult();
												</cfscript>
												<cfoutput>#valueList(rs_selected.institute_short, " | ")#</cfoutput>
										</cfif>
									</td>
									<td><a href="<cfoutput>#buildURL('cetSetting', targetArgs)#</cfoutput>" class="operation edit"></a></td>
								</tr>
							
							</cfloop>

						</tbody>
					</table>
					<!---<div id="dump"></div>--->
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
							
							/* turn usage trigger */
							$("a[usage]", $("#cetList")).click(function(){
								
								var rowid = $(this).attr("rowid");
								var method = $(this).attr("usage");

								var status = $(this).hasClass("yes");

								var newStatus = true;
								
								var $row = $("tr.editRows[rowid='" + rowid + "']", $("#cetList"));
								
								/* 切换状态数据 */
								if (status) {
									newStatus = false;
								}
								
								/* 发送请求 */
								$(this).removeClass("no").removeClass("yes").addClass("waiting");
								
								$.post(
										"<cfoutput>#buildURL('apiCETPropChange')#</cfoutput>", 
										{
											'ex' : rowid,
											'prop' : method,
											'status' : newStatus,
											'seed': (new Date()).getTime()
										}, 
										function(data) {
											
											//alert(data);
											//$("div#dump").html(data);
											result = $.parseJSON(data);
											
											$(this).removeClass("waiting");
											
											/* 刷新允许报考科目数据 */
											if (result.Running) { $("a[usage='Running']", $row).removeClass("no").addClass("yes"); } else { $("a[usage='Running']", $row).removeClass("yes").addClass("no"); }

										});								
							});
							
						});
						// -->
						//]]>
					</script>
				</div>
				
				<cfif len(cetId) and rs_entity.recordCount >
					
					<cfset propAdvice.parseProperty( rs_entity.exam_prop ) />
					
					<div id="Edit" class="tabContent">
					
						<div class="noticeBlock">
							<h3><cfoutput>#rs_entity.exam_name#</cfoutput>报名相关设置</h3>
							<hr/>
						</div>
					
						<form id="formEdit" onSubmit="javascript:return processVerfiyForm('formEdit');" class="formWrapper" method="post" action="<cfoutput>#buildURL('cetUpdateDo')#</cfoutput>">
							
							<input type="hidden" id="ExamID" name="ExamID" value="<cfoutput>#rs_entity.exam_id#</cfoutput>" />
							
							<div class="label">
								<span class="req">*</span><b>科目考试时间</b>
								日期
								<input name="ExamDate" id="ExamDate" type="text" class="typeDate" verification="date" maxlength="10" value="<cfoutput>#datetimeAdvice.formatDateString(rs_entity.exam_date)#</cfoutput>" /><span id="dateTrigger" class="btnCalendar"></span>
								开考时间
								<input name="ExamTime" id="ExamTime" type="text" class="typeTime" verification="time" maxlength="5" value="<cfoutput>#datetimeAdvice.formatTimeString(rs_entity.exam_time, 'HH:MI')#</cfoutput>" />
							</div>
							
							<div class="label">
								<span class="req">*</span><b>允许网上报名</b>
								<input name="Enabled" id="Enabled" type="checkbox" class="typeCheckbox" value="1" <cfif propAdvice.getRunning()>checked="checked"</cfif>/>
							</div>
							
							<hr/>
							
							<div class="label">
								<span class="req">*</span><b>报名时间</b>
								开始日期
								<input name="DateStart" id="DateStart" type="text" class="typeDate" verification="date" maxlength="10" value="<cfoutput>#datetimeAdvice.formatDateString(rs_entity.date_start)#</cfoutput>" /><span id="startTrigger" class="btnCalendar"></span>
								结束日期
								<input name="DateEnd" id="DateEnd" type="text" class="typeDate" verification="date" maxlength="10" value="<cfoutput>#datetimeAdvice.formatDateString(rs_entity.date_end)#</cfoutput>" /><span id="endTrigger" class="btnCalendar"></span>
							</div>
							
							<div class="label">
								<span class="req">*</span><b>网上报名开放时间段</b>
								<input name="FullDay" id="FullDay" type="checkbox" class="typeCheckbox" value="1" <cfif rs_entity.time_start eq "0001" and rs_entity.time_end eq "2359">checked="checked"</cfif>/>全天
								<div id="notFullDay" class="<cfif rs_entity.time_start eq "0001" and rs_entity.time_end eq "2359">hidden_elem</cfif>">
									或 指定时间
									<input name="TimeStart" id="TimeStart" type="text" class="typeTime" verification="time" maxlength="5" value="<cfoutput>#datetimeAdvice.formatTimeString(rs_entity.time_start, 'HH:MI')#</cfoutput>" />
									至
									<input name="TimeEnd" id="TimeEnd" type="text" class="typeTime" verification="time" maxlength="5" value="<cfoutput>#datetimeAdvice.formatTimeString(rs_entity.time_end, 'HH:MI')#</cfoutput>" />
								</div>
							</div>
							
							<div class="label">
								<span class="req">*</span><b>考试费用</b>
								<input name="ExamCharge" id="ExamCharge" type="text" class="typeSmallInt" verification="double" value="<cfoutput>#numberFormat(rs_entity.exam_charge,'__.__')#</cfoutput>" />
							</div>
							
							<hr/>
							
							<div class="label">
								<b>允许选课年级</b>
								<input name="FullGrade" id="FullGrade" type="checkbox" class="typeCheckbox" value="1" <cfif rs_entity.grade_allowed eq "ALL">checked="checked"</cfif>/>所有年级
								<div id="notFullGrade" class="secondRow <cfif rs_entity.grade_allowed eq "ALL">hidden_elem</cfif>">
									或 <br/> 指定年级

									<table>
										<tr>
										<cfset row = 0 />
										<cfset cellPerRow = 5 />
										<cfloop query="rs_grade">
											<cfset row++ />
												<td>
													<input name="targetGrade" type="checkbox" class="typeCheckbox" verification="group" value="<cfoutput>#rs_grade.grade#</cfoutput>" <cfif rs_entity.grade_allowed eq "ALL" or listFind(rs_entity.grade_allowed, rs_grade.grade, ",")>checked="checked"</cfif> /> 
													<cfoutput>#rs_grade.grade#</cfoutput>级
												</td>
											<cfif row mod cellPerRow eq 0>
											</tr>
											<tr>
											</cfif>
										</cfloop>
										<cfif row eq rs_grade.recordCount and rs_grade.recordCount mod cellPerRow>
											<cfloop from="1" to="#cellPerRow-rs_grade.recordCount mod cellPerRow#" index="i">
												<td><!-- <cfoutput>holder<cfoutput>#i#</cfoutput> --></cfoutput></td>
											</cfloop>
										</cfif>
										</tr>
									</table>
									
								</div>
							</div>
							
							<div class="label">
								<b>允许选课学院</b>
								<input name="FullInstitute" id="FullInstitute" type="checkbox" class="typeCheckbox" value="1" <cfif rs_entity.institute_allowed eq "ALL">checked="checked"</cfif>/>所有学院
								<div id="notFullInstitute" class="secondRow <cfif rs_entity.institute_allowed eq "ALL">hidden_elem</cfif>">
									或 <br/> 指定学院
									
									<table>
										<tr>
										<cfset row = 0 />
										<cfset cellPerRow = 9 />
										<cfloop query="rs_institute">
											<cfset row++ />
												<td>
													<input name="targetInstitute" type="checkbox" class="typeCheckbox" verification="group" value="<cfoutput>#rs_institute.institute_id#</cfoutput>" <cfif rs_entity.institute_allowed eq "ALL" or listFind(rs_entity.institute_allowed, rs_institute.institute_id, ",")>checked="checked"</cfif> /> 
													<cfoutput>#rs_institute.institute_short#</cfoutput>
												</td>
											<cfif row mod cellPerRow eq 0>
											</tr>
											<tr>
											</cfif>
										</cfloop>
										<cfif row eq rs_institute.recordCount and rs_institute.recordCount mod cellPerRow>
											<cfloop from="1" to="#cellPerRow-rs_institute.recordCount mod cellPerRow#" index="i">
												<td><!-- <cfoutput>holder<cfoutput>#i#</cfoutput> --></cfoutput></td>
											</cfloop>
										</cfif>
										</tr>
									</table>
									
								</div>
							</div>
							
							<div class="lable">
								<input class="button" type="submit" value="更新" />
								<input id="formReset" class="button1" type="reset" value="重设表格" />
							</div>
							
						</form>
						
						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--
							$(document).ready(function() {
								
								$("#ExamDate").mask("9999-99-99");
								$("#DateStart").mask("9999-99-99");
								$("#DateEnd").mask("9999-99-99");
								
								$("#ExamTime").mask("99:99");
								$("#TimeStart").mask("99:99");
								$("#TimeEnd").mask("99:99");
								
								
								$("#FullDay").change(function(){
									var checked = $(this).prop("checked");
									
									if ( checked ) {
										$("#TimeStart").val("00:01");
										$("#TimeEnd").val("23:59");
										$("#notFullDay").addClass("hidden_elem");
									}
									else {
										$("#notFullDay").removeClass("hidden_elem");
									}
									
								});
								
								$("#FullGrade").change(function(){
									var checked = $(this).prop("checked");
									
									if ( checked ) {
										$("#notFullGrade").addClass("hidden_elem");
									}
									else {
										$("#notFullGrade").removeClass("hidden_elem");
									}
								});
								
								$("#FullInstitute").change(function(){
									var checked = $(this).prop("checked");
									
									if ( checked ) {
										$("#notFullInstitute").addClass("hidden_elem");
									}
									else {
										$("#notFullInstitute").removeClass("hidden_elem");
									}
								});
								
								
								
								Calendar.setup({
									trigger    : "dateTrigger",
									inputField : "ExamDate",
									animation  : false
									});
								Calendar.setup({
									trigger    : "startTrigger",
									inputField : "DateStart",
									animation  : false
									});
								
								Calendar.setup({
									trigger    : "endTrigger",
									inputField : "DateEnd",
									animation  : false
									});

							});
							// -->
							//]]>
						</script>
						
					</div>
					
				</cfif>
				
			</div>
		</li>
	</ul>
</div>

